function loadListTopic(cat_id, dataDiv, possitionDiv, moreDiv) {
	var content = '';
	if ($("#"+dataDiv)) {
		content = $("#"+dataDiv).html();
	}
	if ( content == '') {
		content = getTopicList(cat_id, dataDiv, possitionDiv, moreDiv);
	} else {
		$("#"+possitionDiv).html(content);
	}
	if (content != '' && content != null && content != 'undefined' && content != '<li class="cdp-product"> Hiện chưa có sản phẩm nào trong nhóm này.</li>') {
		$("#"+moreDiv).show();
	}
	else{
		$("#"+moreDiv).hide();
	} 
	
}

function getTopicList(cat_id, dataDiv, possitionDiv, moreDiv) {
	if (cat_id == null || cat_id == 0) {
		return;
	}
	if (possitionDiv == null) {
		return;
	}

	if (dataDiv == null) {
		return;
	}
	$("#"+moreDiv).html($("#view_more_"+cat_id).html());
	$.get(baseurl+"/supercategory/ajaxgettopiclist",
		{
			cat_id: cat_id
			
		},
		function(result){
			var html = '';
			if (result != null) {
				var data = result.data;
				if (data != null) {
					var objTopic = '';
					var i = 1;
					$.each(data, function(index, value){
						objTopic = value;
						html += createTopicElement(objTopic, i);
						i++;
					});
				$("#"+moreDiv).show();
				}
				else {
					html += '<li class="cdp-product"> Hiện chưa có sản phẩm nào trong nhóm này.</li>';
				}
			}
			$("#"+possitionDiv).html(html);
			$("#"+dataDiv).html(html);
		},
	"json");
}

function createTopicElement(objTopic, order) {
	var element =   '<li class="cdp-product ';
	if (objTopic.vip_level > 0) {
		element += 'vip-att';
	}
	element += '">'+
			'<figure class="pic"><a href="'+objTopic.topic_url+'"><img src="'+objTopic.main_photo_url+'" alt="Sản phẩm" /></a></figure>'+
				'<div class="img-vip"><img src="'+imgurl+'/v2/icon_vipStar.gif" width="18" height="32" alt="VIP"></div>'+
				'<h2 class="name-product"><a href="'+objTopic.topic_url+'">'+objTopic.topic_name+'</a></h2>'+
				'<p class="price">'+objTopic.range_price+ ' VNĐ</p>'+
			'</li>';
	return element;
}

jQuery().ready(function(){
	$("ul#ul1 li").click(function(){
	  // If this isn't already active
	  if (!$(this).hasClass("active")) {
		// Remove the class from anything that is active
		$("ul#ul1 li.active").removeClass("active");
		// And make this active
		$(this).addClass("active");
	  }
	});

	$("ul#ul2 li").click(function(){
	  // If this isn't already active
	  if (!$(this).hasClass("active")) {
		// Remove the class from anything that is active
		$("ul#ul2 li.active").removeClass("active");
		// And make this active
		$(this).addClass("active");
	  }
	});

	$("ul#ul3 li").click(function(){
	  // If this isn't already active
	  if (!$(this).hasClass("active")) {
		// Remove the class from anything that is active
		$("ul#ul3 li.active").removeClass("active");
		// And make this active
		$(this).addClass("active");
	  }
	});
	
	$(".selected-box").simpleSlider({item:1, itemSelector: ".selected-product"});
});